//
// Created by DengLibin on 2018/12/13 0013.
//

/**
	容器 集合set 元素唯一，自动排序 (默认从小到大)不能按照下标插入元素
	multiset中同一值可以出现多次。
*/
#include <iostream>
#include <set>
#include <string>
#include <functional>
using namespace std;
class SetStudent
{
public:
    int age;
    string name;
    SetStudent(int age, string name)
    {
        this->age = age;
        this->name = name;
    }
};
//仿函数(函数对象 重载() )
struct funcStudent
{
    //重载()符
    bool operator()(const SetStudent &left, const SetStudent &right)
    {
        return left.age < right.age;
    }
};
void testSet()
{
    set<string> s;//从小到大
    set<string, less<string>> s3; //从小到大
    set<string, greater<string>> s4;//从大到小
    s.insert("a");
    s.insert("c");
    s.insert("b");

    s.erase(s.begin());//移除元素



    s3.insert("a");
    s3.insert("c");
    s3.insert("b");


    s4.insert("a");
    s4.insert("c");
    s4.insert("b");


    for (set<string, greater<string>>::iterator it = s4.begin(); it != s4.end(); it++)
    {
        cout << *it << ",";
    }//bca
}
//对象集合,排序，引入仿函数
void studentSet()
{
    set<SetStudent, funcStudent> s;//从小到大排序
    SetStudent s1(34, "张三");
    s.insert(s1);
    SetStudent s2(32, "李四");
    s.insert(s2);
    SetStudent s3(36, "王五");
    s.insert(s3);
    for (set<SetStudent>::iterator it = s.begin(); it != s.end(); it++)
    {
        cout << it->age << "--" << it->name << "\n";
    }
}
//set的查找
void findSet()
{
    set<int> s;
    for (int i = 0; i < 10; i++)
    {
        s.insert(i);
    }
    set<int>::iterator it = s.find(5);
    cout << "查找5: " << *it << endl;//5

    set<int>::iterator it2 = s.lower_bound(5);
    cout << "lower_bound5: " << *it2 << endl;//5

    set<int>::iterator it3 = s.upper_bound(5);
    cout << "upper_bound5: " << *it3 << endl;//6

    pair<set<int>::iterator, set<int>::iterator> pa = s.equal_range(5);
    cout << "pair_first: " << *(pa.first) << endl;//5
    cout << "pair_second: " << *(pa.second) << endl;//6
}
/**
 * 可重复的set
 */
void myMultiset()
{
    multiset<string,greater<string>> ms; //可重复 从大到小排列
    ms.insert("hello");
    ms.insert("world");
    ms.insert("hello");
    for (multiset<string>::iterator it = ms.begin(); it != ms.end(); it++)
    {
        cout << *it << endl;
    }
}
int main28()
{
    //studentSet();
    myMultiset();
    return 0;
}
